package logic

import (
	"context"
	"fmt"
	"health/model/mysql"

	"health/registerrpc/internal/svc"
	"health/registerrpc/registerrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowLogic {
	return &ShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShowLogic) Show(in *registerrpc.ShowRequest) (*registerrpc.ShowResponse, error) {
	// todo: add your logic here and delete this line

	var show mysql.Register
	mysql.DB.Debug().Where("id = ?", in.Id).Find(&show)
	if show.ID == 0 {
		return nil, fmt.Errorf("该预约不存在")
	}

	return &registerrpc.ShowResponse{
		Id:     int64(show.ID),
		Doctor: show.Doctor,
		Price:  float32(show.Price),
		Times:  show.Times,
		Types:  show.Types,
	}, nil
}
